#ifndef SOURCEMANAGE_H
#define SOURCEMANAGE_H

#include <QMutex>
#include <QMutexLocker>

#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
#include <QFileInfo>

#include "queueexp.h"
#include "filemanage.h"
#include "netsendreceive.h"
#include "netdealwith.h"
#include "experiment.h"
class SourceManage;
#define SM SourceManage::GetInstance()

class SourceManage
{
public:
    static SourceManage *GetInstance()
    {
       if(!instance)
        {
            //QMutexLocker locker(&mutex);
            if(!instance)
            {
                instance=new SourceManage;
            }
       }
       return instance;
    }

    void Init();
    AnalyteDataBase *GetAnalyteDataBase();
    CalRatio GetCalStandard();
    CalRatio GetCalHigh();
    CalRatio GetCalCross();
    QList<TuneResult> GetTuneResults();
    bool SetTune(int index,bool state);
    QueueExp *GetQueueExp();
    WorkFlow GetWorkFlow();
    WorkFlow *GetWorkFlowPtr();
    bool SetWorkFlow(WorkFlow flow);
    void SetSystemState(SystemState);
    SystemState GetSystemState();
    void SetWorkStep(WorkStep);
    WorkStep GetWorkStep();
    WorkStep *GetWorkStepePtr();
    LimitValue GetLimitValue();
    void SetLimitValue(LimitValue);

    NetSendReceive *GetNetSendReceive();
    NetDealwith *GetNetDealwith();

    QStringList GetOption(QString);

    void AddOpenedExps(QString ,Experiment);
    void RemoveOpenedExps(QString path);
    Experiment *GetOpenedExps(QString);

    QHash<QString,QStringList> options;//
 private:
    SourceManage();

    AnalyteDataBase analyteDataBase;//全局元素库

    //set save
    CalRatio massCalStandard;// 标准：质量校正系数（内部存储一组数据，界面显示文件夹结果）
    CalRatio massCalHigh;//高标：
    CalRatio crossCal;// 交叉校正系数
    QList<TuneResult> tuneResults;//仪器参数：调谐参数
    QueueExp queueExps;//更改保存 序列和各实验
    WorkFlow workFlow;

    QHash<QString,Experiment> openedExps;//记录

    //temp
    WorkStep workStepSet;//
    SystemState systemState;
    LimitValue limitValue;
    //序列号
    //版本
    //上下限值
    //报警码
    //建立曲线
    //安全质量

    NetSendReceive *pNetSendReceive;
    NetDealwith *pNetDealwith;

    static QMutex mutex;
    static SourceManage* instance;
    class QGarbo
    {
    public:
     ~QGarbo()
        {
         //qDebug()<<"SourceManage Free";
            if(instance!=NULL)
            {
                //delete pNetSendReceive;
                //delete pNetDealwith;

                delete instance;
                instance=NULL;
            }

        }
     };
     static QGarbo garbo;
};

#endif // SOURCEMANAGE_H
